<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>思途CMS3.0</title>
 {template 'stourtravel/public/public_js'}
   {php echo Common::getCss('style.css,base.css,base2.css,plist.css,base_new.css'); }
   {php echo Common::getCss('ext-theme-neptune-all-debug.css','js/extjs/resources/ext-theme-neptune/'); }
    
   {php echo Common::getScript("uploadify/jquery.uploadify.min.js,jquery.buttonbox.js,choose.js"); }
   {php echo Common::getCss('uploadify.css','js/uploadify/'); }
   <style>
       .info-bar{
           width:100%;
           float:left;
           height:33px;
       }
       .info-bar span{
           float: left;
           height: 33px;
           line-height: 33px;
           margin-left:30px;
       }
   </style>
</head>
<body style="overflow:hidden">
<table class="content-tab">
   <tr>
    <td width="119px" class="content-lt-td"  valign="top">
     {template 'stourtravel/public/leftnav'}
    <!--右侧内容区-->
    </td>
    <td valign="top" class="content-rt-td" style="overflow:hidden">
		<div class="cfg-header-bar">
			<div class="cfg-header-tab">
				<span class="item" id="basic" onclick="window.location.href=SITEURL+'{$cmsurl}fenxiao/admin/fenxiao/edit/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}memberid/{$memberid}'">基础信息</span>
                <span class="item" onclick="window.location.href=SITEURL+'{$cmsurl}fenxiao/admin/fenxiao/suborder/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}?memberid={$memberid}'">下级推广订单</span>
                <span class="item on" onclick="window.location.href=SITEURL+'{$cmsurl}fenxiao/admin/fenxiao/submember/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}?memberid={$memberid}'">分销关系</span>
                <span class="item" onclick="window.location.href=SITEURL+'{$cmsurl}fenxiao/admin/fenxiao/record/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}?memberid={$memberid}'">佣金记录</span>
			</div>
			<a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>	
		</div>
		<div class="info-bar">
			<span>下级总数：{$sub_total}</span>
			<span>直接下级：{$sub_first_total}</span>
			<span>二级下级：{$sub_second_total}</span>
			{if $level_num==3}<span>三级下级：{$sub_third_total}</span>{/if}
            {if !empty($first_parent_member)}
            <span>直接上级: <a href="javascript:;" class="c-orange" onclick="showParent({$first_parent_member['mid']},'{$first_parent_member['nickname']}')">{$first_parent_member['nickname']}</a></span>
            {/if}
            {if !empty($second_parent_member)}
            <span>间接上级: <a href="javascript:;" class="c-orange" onclick="showParent({$second_parent_member['mid']},'{$second_parent_member['nickname']}')">{$second_parent_member['nickname']}</a></span>
            {/if}
            {if $level_num==3 && !empty($third_parent_member)}<span>三级上级: <a href="javascript:;" class="c-orange" onclick="showParent({$third_parent_member['mid']},'{$third_parent_member['nickname']}')">{$third_parent_member['nickname']}</a></span>{/if}
		</div>
		<div class="cfg-search-bar fl">
			<span class="select-box w150 mt-3 ml-10 fl">
				<select name="group" onchange="goSearch(this)" class="select">
                    <option value="">全部下级</option>
                    <option value="1">直接下级</option>
                    <option value="2">二级下级</option>
                    {if $level_num==3}
                    <option value="3">三级下级</option>
                    {/if}
                </select>
			</span>
			<div class="cfg-header-search">
				<input type="text" id="searchkey" value="" datadef="会员账号" placeholder="分销商账号或名称" class="search-text">
				<a href="javascript:;" class="search-btn" onclick="CHOOSE.searchKeyword()">搜索</a>
                <a href="javascript:;" class=" btn btn-primary radius" style="margin-left: 10px" onclick="change_fxcode()">变更关系</a>
			</div>
		</div>	
		
	 	<div id="product_grid_panel" class="content-nrt">
	    
	 	</div>
  </td>
  </tr>
 </table> 
<script>


   // window.kindmenu = {$kindmenu};//分类设置菜单

   var memberid="{$memberid}";
  Ext.onReady(
    function() 
    {
		 Ext.tip.QuickTipManager.init();

		//产品store
        window.product_store=Ext.create('Ext.data.Store',{

		 fields:[
             'id',
             'nickname',
             'account',
             'id',
             'subnum',
             'fxjointime',
             'fxgroup_name',
             'total',
             'sub_level',
             'fxrank_name'
         ],
         proxy:{
		   type:'ajax',
           extraParams: {memberid: memberid},
		   api: {
              read: SITEURL+'fenxiao/admin/fenxiao/submember/action/read',  //读取数据的URL
			  update:SITEURL+'fenxiao/admin/fenxiao/submember/action/save',
			  destroy:SITEURL+'fenxiao/admin/fenxiao/submember/action/delete'
              },
		      reader:{
                type: 'json',   //获取数据的格式 
                root: 'lists',
                totalProperty: 'total'
                }	
	         },
		 remoteSort:true,	 
		 pageSize:30,	 	
         autoLoad:true,
		 listeners:{
             load:function( store, records, successful, eOpts )
             {
                 if(!successful){
                     ST.Util.showMsg("{__('norightmsg')}",5,1000);
                 }
                 var pageHtml=ST.Util.page(store.pageSize,store.currentPage,store.getTotalCount(),10);
                 $("#line_page").html(pageHtml);
                 window.product_grid.doLayout();
                 $(".pageContainer .pagePart a").click(function () {
                     var page = $(this).attr('page');
                     product_store.loadPage(page);
                 });

             }
		 }
		  
       });
	   
	  //产品列表 
	  window.product_grid=Ext.create('Ext.grid.Panel',{ 
	   store:product_store,
	   renderTo:'product_grid_panel',
	   border:0,
	   bodyBorder:0,
	   bodyStyle:'border-width:0px',
	   scroll:'vertical',
	   bbar: Ext.create('Ext.toolbar.Toolbar', {
                    store: product_store,  //这个和grid用的store一样
                    displayInfo: true,
                    emptyMsg: "没有数据了",
					items:[
                        {
                            xtype:'panel',
                            id:'listPagePanel',
                            html:'<div id="line_page"></div>'
                       },
					  {
						  xtype:'combo',
						  fieldLabel:'每页显示数量',
						  width:170,
						  labelAlign:'right',
						  forceSelection:true,
						  value:30,
						  store:{fields:['num'],data:[{num:30},{num:60},{num:100}]},
						  displayField:'num',
						  valueField:'num',
						  listeners:{
							  select:CHOOSE.changeNum
						  }
					  }
					
					],
				  listeners: {
						single: true,
						render: function(bar) {
							var items = this.items;
                            bar.insert(0,Ext.create('Ext.toolbar.Fill'));
						}
					}	
                 }), 		 			 
	   columns:[
           {
               text:'选择',
               width:'6%',
               tdCls:'line-ch',
               align:'center',
               dataIndex:'id',
               menuDisabled:true,
               sortable:false,
               border:0,
               renderer : function(value, metadata,record) {
                   return  "<input type='checkbox' class='product_check' style='cursor:pointer' id='box_"+value+"' value='"+value+"'/>";
               }
           },
           {
               text:'昵称',
               width:'15%',
               dataIndex:'nickname',
               align:'center',
               menuDisabled:true,
               border:0,
               sortable:false,
               renderer : function(value, metadata,record) {
                   return value;
               }
           },
               {
                   text:'账号',
                   width:'15%',
                   dataIndex:'account',
                   id:'column_series',
                   align:'center',
                   menuDisabled:true,
                   border:0,
                   sortable:false,
                   renderer : function(value, metadata,record) {
                       return value;
                   }
               },
           {
               text:'分销商等级',
               width:'15%',
               dataIndex:'fxrank_name',
               align:'center',
               menuDisabled:true,
               border:0,
               sortable:false,
               renderer : function(value, metadata,record) {
                   return value;
               }
           },
           {
               text:'分销商分组',
               width:'15%',
               dataIndex:'fxgroup_name',
               align:'center',
               menuDisabled:true,
               border:0,
               sortable:false,
               renderer : function(value, metadata,record) {
                   return value;
               }
           },
           {
               text:'下级关系',
               width:'14%',
               dataIndex:'sub_level',
               align:'center',
               menuDisabled:true,
               border:0,
               sortable:false,
               renderer : function(value, metadata,record) {
                   var name='';
                   switch(value)
                   {
                       case 1:
                         name='直接下级';
                           break;
                       case 2:
                          name='二级下级';
                           break;
                       case 3:
                           name='三级下级';
                           break;
                   }
                   return name;
               }
           },
           {
               text:'返佣金额',
               width:'10%',
               dataIndex:'total',
               align:'center',
               menuDisabled:true,
               border:0,
               sortable:false,
               renderer : function(value, metadata,record) {
                   return value;
               }
           }

			,
           {
               text:'成为分销商时间',
               width:'10%',
               dataIndex:'fxjointime',
               align:'center',
               cls:'mod-1 sort-col',
               sortable:true,
               menuDisabled:true
           }
             ],
			 listeners:{
		            boxready:function()
		            {
                        var height=Ext.dom.Element.getViewportHeight();
					   this.maxHeight=height-106;
					   this.doLayout();
		            },
					afterlayout:function(grid)
					{

						window.product_store.each(function(record){
				         id=record.get('id');


					   });
					   
					   var data_height=0;
					   try{
					     data_height=grid.getView().getEl().down('.x-grid-table').getHeight();
					   }catch(e)
					   {

					   }
					  var height=Ext.dom.Element.getViewportHeight();
					// console.log(data_height+'---'+height);
					  if(data_height>height-106)
					  {
						  window.has_biged=true;
						  grid.height=height-106;
					  }
					  else if(data_height<height-106)
					  {
						  if(window.has_biged)
						  {
							//delete window.product_grid.height;
							window.has_biged=false;  
							grid.doLayout();
						  }
					  }
				  }
			 },
			 plugins: [
                Ext.create('Ext.grid.plugin.CellEditing', {
                  clicksToEdit:2,
                  listeners:{
					 edit:function(editor, e)
					 {
						   var id=e.record.get('id');
						 //  var view_el=window.product_grid.getView().getEl();
						 // view_el.scrollBy(0,this.scroll_top,false);
						updateField(0,id,e.field,e.value,0);
						return false;
						  
					 },
					 beforeedit:function(editor,e)
					 {

						// var view_el=window.product_grid.getView().getEl();
	                     //this.scroll_top=view_el.getScrollTop();				   
	 
					 }
				 }
               })
             ],
			viewConfig:{
				//enableTextSelection:true
				}	   
	   });
	   
	  
	  
	})
	
	//实现动态窗口大小
  Ext.EventManager.onWindowResize(function(){ 
       var height=Ext.dom.Element.getViewportHeight(); 
	   var data_height=window.product_grid.getView().getEl().down('.x-grid-table').getHeight();
	   if(data_height>height-106)
	     window.product_grid.height=(height-106);
	   else
	      delete window.product_grid.height;
	   window.product_grid.doLayout();
	   
	 })

   function setfxcode(){
       window.location.reload()
   }
	

  function change_fxcode(){
      let ids=[]
      $(".product_check:checked").each(function(index,element){
          var id=$(element).val();
          ids.push(id);
      });
      ids=ids.join(',')
      if(!ids){
          ST.Util.showMsg('请选择直属下级',5);
          return
      }
      ST.Util.showBox("变更分销商",SITEURL+'fenxiao/admin/fenxiao/dialog_change_fxcode?ids='+ids+'&mid='+"{$memberid}",400,200,null,null,document,{loadWindow: window, loadCallback: setfxcode});
  }

 
  //更新套餐的字段，并显示相应的text框，仅用于租车的支付方式
  function updateMixField(ele,id,field,value,type)
  {
	  if(type=='select')
	  {
		  var val=Ext.get(ele).getValue();
		 if(val==2)
		  Ext.get(ele).parent('table').down('input').show();
		 else
		  Ext.get(ele).parent('table').down('input').hide();  
	  }
	  updateField(ele,id,field,value,type);
  }
   //去搜索
   function goSearch(ele)
   {
       var name=$(ele).attr('name');
       var val=$(ele).val();
       window.product_store.getProxy().setExtraParam(name, val);
       window.product_store.loadPage(1);
   }

   //去搜索
    function showParent(mid,account)
    {
        var url = SITEURL+'fenxiao/admin/fenxiao/edit/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}memberid/'+mid;
        parent.window.addTab('修改：'+account,url,1);
    }
 
</script>

</body>
</html>
